# -*- coding=utf-8 -*-
# @time:2021/8/7
# @phone:15874198829
# @author:码尚教育_星瑶
from appium  import webdriver
from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
"""
TouchAction  触屏操作
"""
desired_caps={
    "automationName":"UiAutomator2", #默认框架
    "platformName":"Android", #指定操作系统
"platformVersion":"5.1.1",#指定系统版本
    "deviceName":"127.0.0.1:62001",#指定设备名称
    "appPackage":"com.mymoney",#被操作的应用程序包名
    "appActivity":"com.mymoney.biz.main.MainActivity" , #启动页面
    "noReset":"True"   #  为true 不重置  为false 重置
}
# 发送指令给appium server
driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
# 实现操作：
# 点击更多
many_loc=(MobileBy.ID,"com.mymoney:id/nav_setting_btn")
WebDriverWait(driver,15).until(EC.presence_of_element_located(many_loc))
driver.find_element(*many_loc).click()

size=driver.get_window_size()
x=size["width"]
y=size["height"]
# 实现下滑
driver.swipe(start_x=x*0.9,end_x=x*0.9,start_y=x*0.2,end_y=x*0.7,duration=1000)
# 点击高级
gj_loc=(MobileBy.ANDROID_UIAUTOMATOR,'new UiSelector().text("高级")')
WebDriverWait(driver,15).until(EC.presence_of_element_located(gj_loc))
driver.find_element(*gj_loc).click()
# 点击	密码与手势密码
pswd_loc=(MobileBy.ANDROID_UIAUTOMATOR,'new UiSelector().text("密码与手势密码")')
WebDriverWait(driver,15).until(EC.presence_of_element_located(pswd_loc))
driver.find_element(*pswd_loc).click()
# 	点击手势密码保护
pswdbh_loc=(MobileBy.ANDROID_UIAUTOMATOR,'new UiSelector().text("手势密码保护")')
WebDriverWait(driver,15).until(EC.presence_of_element_located(pswdbh_loc))
driver.find_element(*pswdbh_loc).click()

# TouchAction逻辑等同web自动测试ActionChains  实现手势密保设置的触屏操作

for x in range(2):
    TouchAction(driver).press(x=337,y=384).wait(1000).move_to(x=541,y=384).wait(1000).move_to(x=734,y=384).wait(1000)\
    .move_to(x=531,y=577).wait(1000).move_to(x=337,y=777).wait(1000).move_to(x=541,y=777).wait(1000).move_to(x=739,y=777).wait(1000).release().perform()


# 多点触控的操作  下节课跟大家讲